/*
 * channelserver.h
 *
 *  Created on: 2013. 7. 19.
 *      Author: jjaehuny
 */

#ifndef CHANNELSERVER_H_
#define CHANNELSERVER_H_

#include <Dispatcher/Static.h>
#include <Network/Network.h>


#include "../idl/Location.h"

#include <string>

namespace CacheServer {

class ChannelServer : public Dispatcher::Session
{
public:
	ChannelServer();
	virtual ~ChannelServer();

public:
	template <class MSG> void SendMsg(const MSG& msg)
	{
		Dispatcher::ListenHandler<Session, Network::Packet>::SendMsg(this, msg);
	}


public:
	//init_state _init_state;
};

struct Msg
{
public:
	static const int s_MaxUser = 20000;
	static const int s_Mode = 1;

public:

	static void SendRegistAck(ChannelServer * pChannelServer, uint32_t seq, LocationResult result, const char * strError);
	static void SendUnRegistAck(ChannelServer * pChannelServer, uint32_t seq, LocationResult result, const char * strError);
	static void SendChatAck(ChannelServer * pChannelServer, uint32_t sender_seq, uint32_t receiver_seq, LocationResult result);
	static void SendRecallAck(ChannelServer * pChannelServer, uint32_t sender_seq, uint32_t receiver_seq, LocationResult result);
	static void SendKick(ChannelServer * pChannelServer, uint32_t kickUserSeq);
	static void SendSetMainCharaterInfoAck(ChannelServer * pChannelServer, uint32_t seq, int16_t result);
	static void SendGetMainCharaterInfoAck(ChannelServer * pChannelServer, uint32_t seq, int16_t result);
	static void SendGetMainCharaterInfoAck_V2(ChannelServer * pChannelServer, uint32_t seq, int16_t result);

public:
	static void OnRegistSyn(Dispatcher::Session* pSession, ::Network::Packet * pPacket );
	static void OnUnRegistSyn(Dispatcher::Session* pSession, ::Network::Packet * pPacket );

	static void Chat(Dispatcher::Session* pSession, ::Network::Packet * pPacket );
	static void Recall(Dispatcher::Session* pSession, ::Network::Packet * pPacket );
	static void OnRecallAck(Dispatcher::Session* pSession, ::Network::Packet * pPacket );

	static void Close(Dispatcher::Session* pSession, ::Network::Packet * pPacket );

	static void TradeItemSoldout(Dispatcher::Session* pSession, ::Network::Packet * pPacket );

	static void SetMainCharacterInfoSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void GetMainCharacterInfoSyn(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
	static void GetMainCharacterInfoSyn_V2(Dispatcher::Session * pSession, ::Network::Packet * pPacket);
};

struct init_state : public Dispatcher::Session::State
{
public:
	init_state()
	{
		AddCommand(RegistSyn::MSG_ID, Msg::OnRegistSyn);
		AddCommand(UnRegistSyn::MSG_ID, Msg::OnUnRegistSyn);
		AddCommand(ChatSyn::MSG_ID, Msg::Chat);
		AddCommand(RecallSyn::MSG_ID, Msg::Recall);
		AddCommand(RecallAck::MSG_ID, Msg::OnRecallAck);
		AddCommand(TradeItemSoldoutSyn::MSG_ID, Msg::TradeItemSoldout);
		AddCommand(SetMainCharacterInfoSyn::MSG_ID, Msg::SetMainCharacterInfoSyn);
		AddCommand(GetMainCharacterInfoSyn::MSG_ID, Msg::GetMainCharacterInfoSyn);
		AddCommand(GetMainCharacterInfoSyn_V2::MSG_ID, Msg::GetMainCharacterInfoSyn_V2);

		AddCommand(1, Msg::Close);
	}
};

} /* namespace cacheserver */
#endif /* CHANNELSERVER_H_ */
